package org.nfIt.controller;

import com.github.pagehelper.PageInfo;
import org.nfIt.entity.product.Brand;
import org.nfIt.service.BrandService;
import org.nfIt.vo.common.Result;
import org.nfIt.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClossName:BrandController
 * Pakage:org.nfIt.controller
 * Description
 *
 * @Author L
 * @Create 2024/8/9 11:45
 * @Version 2023.1.3
 */
@RestController
@RequestMapping(value="/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService ;


    /**
     * 查询所有品牌
     */
    @GetMapping("/findAll")
    public Result findAll(){
        List<Brand> list = brandService.findAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询全部品牌列表
     * @param page 当前页
     * @param limit 每页记录数
     */
    @GetMapping("/{page}/{limit}")
    public Result<PageInfo<Brand>> findByPage(@PathVariable Integer page, @PathVariable Integer limit) {
        PageInfo<Brand> pageInfo = brandService.findByPage(page, limit);
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }


    /**
     * 添加品牌
     * @param brand 实体
     */
    @PostMapping("/save")
    public Result save(@RequestBody Brand brand) {
         brandService.save(brand);
         return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}